package com.nbpt;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class denglu extends Activity implements AdapterView.OnItemClickListener {

    private GridView gridView;

    String FruitName[]={"智能家居","智能商超","天气预报","设置中心"};
    int image[]={R.drawable.icon_home,
            R.drawable.icon_shopping,
            R.drawable.icon_weather,
            R.drawable.icon_settings,
    };

    String[] from = {"img","name"};//map对应键值名称
    int[] to={R.id.img_smart,R.id.txt_smart};
    List<Map<String,Object>> imageList = new ArrayList<Map<String,Object>>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_denglu);
        gridView = findViewById(R.id.gridView);

//        List<Map<String,Object>> imageList = new ArrayList<Map<String,Object>>();

        for (int i=0;i<image.length;i++)
        {
            Map<String,Object> map = new HashMap<String, Object>();
            map.put("img",image[i]);
            map.put("name",FruitName[i]);
            imageList.add(map);
        }
        SimpleAdapter adapter = new SimpleAdapter(this,imageList,R.layout.grid_two_item,from,to);

    //    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,FruitName);
        gridView.setAdapter(adapter);
        gridView.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        Toast.makeText(denglu.this,"点击了"+FruitName[i],Toast.LENGTH_SHORT).show();
        if (i==0)
        {
            Intent intent = new Intent(this, zhinengjiaju.class);
            startActivityForResult(intent, 0);
        }

        if (i==3){
            Intent intent = new Intent(this, shezhi.class);
            startActivityForResult(intent, 0);
        }
    }

}
